package com.jiuzhou.guanwang.jzcp.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jiuzhou.guanwang.jzcp.R;
import com.jiuzhou.guanwang.jzcp.activity.TeamRankActivity;
import com.jiuzhou.guanwang.jzcp.activity.TrandActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

public class FindFragment extends Fragment {
    @BindView(R.id.tv_title_left)
    TextView tvTitleLeft;
    @BindView(R.id.title)
    TextView title;
    @BindView(R.id.img_title_right)
    ImageView imgTitleRight;
    @BindView(R.id.tv_title_right)
    TextView tvTitleRight;
    @BindView(R.id.head)
    RelativeLayout head;
    @BindView(R.id.ll_team)
    LinearLayout llTeam;
    @BindView(R.id.ll_forcast)
    LinearLayout llForcast;
    Unbinder unbinder1;
    private View rootView;
    private Unbinder unbinder;

    public static FindFragment newInstance(String info) {
        Bundle args = new Bundle();
        FindFragment fragment = new FindFragment();
        args.putString("info", info);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle bundle = getArguments();
        if (bundle != null) {
            String name = bundle.get("info").toString();
        }
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        if (rootView == null) {
            rootView = inflater.inflate(R.layout.fragment_find, null);
            unbinder = ButterKnife.bind(this, rootView);
            initView();
            initData();
        } else {
            // 缓存的rootView需要判断是否已经被加过parent，如果有parent需要从parent删除，
            // 要不然会发生这个rootview已经有parent的错误。
            ViewGroup parent = (ViewGroup) rootView.getParent();
            if (parent != null) {
                parent.removeView(rootView);
            }
        }

        unbinder1 = ButterKnife.bind(this, rootView);
        return rootView;
    }

    private void initView() {
    }


    private void initData() {
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }


    @OnClick({R.id.ll_team, R.id.ll_forcast})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ll_team:
                Intent intent= new Intent(getActivity(), TeamRankActivity.class);
                getActivity().startActivity(intent);
                break;
            case R.id.ll_forcast:
                Intent intent2= new Intent(getActivity(), TrandActivity.class);
                getActivity().startActivity(intent2);
                break;
        }
    }
}
